<template>
  <views class="invoice_manager_log">
    <viewTitle :title="'开票记录'" :border="false"></viewTitle>
    <!-- 搜索栏 -->

    <div class="search flex flexC">

      <!-- 充值时间  按钮 (查询、重置、导出列表、录单)-->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="pay_btn flex">
          <!-- 充值时间 -->
          <div class="pay_time flex flexR center">
            <el-form-item label="申请时间:">
              <el-date-picker
                      v-model="apply_time"
                      type="datetimerange"
                      align="right"
                      :default-time="['0:00:00','23:59:59']"
                      unlink-panels
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      :picker-options="pickerOptions"
                      @change="changeTime"
              ></el-date-picker>
            </el-form-item>
          </div>
          <!-- 按钮（查询、重置、导出列表、录单）  录单属于服务商端 -->
          <el-form-item>
            <div class="flex flexR pay_btn_list">
              <el-button type="primary" @click="getData" icon="el-icon-search"  >查看</el-button>
              <el-button @click="reset()" icon="el-icon-refresh">重置</el-button>
              <el-button type="danger" @click="exportExcel" icon="el-icon-download">导出列表</el-button>
            </div>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="search_input flex flexR center">
      <div :style="{marginLeft:'15px'}" class="show-title-money flex flexR">
        <div class="flex flexR">
          <div>交易笔数</div>
          <div class="price">{{pagination.total_count}}</div>
          <div>笔</div>
        </div>
        <div class="flex flexR">
          <div>交易金额(元)</div>
          <div class="price">￥{{pagination.summy ? $splitK(pagination.summy) : ''}}</div>
        </div>
      </div>
    </div>
    <!-- 表格 -->
    <!-- 展示列表 -->
    <div class="table_list">
      <el-table
              border
              :data="tableData"
              style="width: 100%;max-width:none;"
              :header-cell-style="getRowClass"
              :select-on-indeterminate="true"
              :fit="true"
              :lazy="true"
              @row-click="clickRow"
              max-height="450"
      >
        <el-table-column fixed type="index" label="序号" width="100"></el-table-column>
        <el-table-column fixed prop="create_time" label="申请时间" width="200"></el-table-column>
        <el-table-column prop="facilitator_name" label="服务商名称" width="150"></el-table-column>
        <el-table-column prop="enterprise_name" label="发票抬头" width="120"></el-table-column>
        <el-table-column prop="money" label="发票金额" width="300"></el-table-column>
        <el-table-column prop="invoice_type" label="发票类型" width="120"></el-table-column>
        <el-table-column prop="a" label="收货地址" width="auto"></el-table-column>
        <el-table-column prop="invoice_status" label="发票状态" width="150"></el-table-column>
        <el-table-column prop="open_upload_img" label="履约确认函" width="150">
          <template slot-scope="scope">
            <el-image
                    style="width: 50px; height: 50px"
                    :src="scope.row.apply_img"
                    :preview-src-list="[scope.row.apply_img]"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="120"></el-table-column>
        <el-table-column prop="zip" label="操作" fixed="right" width="200" >
          <template slot-scope="scope">
            <div class="table_operation">
              <el-button type="primary" @click="toDetail(scope)" >查看</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="flex flexR paging">
      <el-pagination
        style="background:#fff; padding:10px 0"
        background
        layout="total, sizes,prev, pager, next, jumper"
        @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
        @current-change="(page_size) => {this.pagination.page_start = page_size;this.getData()}"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pagination.page_size"
        :total="pagination.total_count"
        :current-page="pagination.current_page"
        :page-count="pagination.page_count"
      ></el-pagination>
    </div>
  </views>
</template>



<script>
export default {
  data() {
    return {
      tableData: [],
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      },
      download_url: "",
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      apply_time:[],
      form:{
          has_invoice: 1, //  开票状态列表
          created_time_start: "", //    申请时间
          created_time_end: "", //    申请时间
      }
    };
  },
  methods: {
    changeTime() {
      if (this.apply_time) {
        this.form.created_time_start = this.apply_time[0]/1000;
        this.form.created_time_end = this.apply_time[1]/1000;
      } else {
        this.form.created_time_start = "";
        this.form.created_time_end = "";
      }
    },      
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //     点击单行
    clickRow(row, column, event) {
      console.log(row, column, event);
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    //    去开票记录列表
    toDetail(scope) {
        this.$toRoutePath({
            path: "/invoice_log/invoice_look",
            edit: true,
            query: { enterprise_invoice_id: scope.row.enterprise_invoice_id }
        });
    },
    //   查询
    getData() {
        this.form.pagination = this.pagination;
        let { code, msg, data } = this.$api.sendSync(
            this.$mapapi.finvoiceList,
            this.form
        );
        if (code != 200 && code != 501) {
            this.$message.error(msg);
            return;
        }
        this.tableData = data.list;
        this.download_url = data.download_url;
        this.pagination = data.pagination;
    },
    //   重置
    reset() {
      this.make_time = []; //  开票时间
      this.start_time = ""; //  开始时间
      this.end_time = ""; //  结束时间
    },
    //   导出
    exportExcel() {
      this.$import_excal(this.download_url || "");
    }
  },
  created() {
      if(this.$route.query.enterprise_id)
          this.form.enterprise_id = this.$route.query.enterprise_id
  },
  mounted() {
       this.$setRouteTitle();
       this.getData()
  }
};
</script>



<style lang="less"  :scope="true"   src="@/style/invoice/invoice_manager_log.less">
</style>